<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页</title>
</head>
<body>
    用户名：<input id="username" type="text"><span id="user_msg"></span><br>
    密码：<input id="password" type="password"><span id="pwd_msg"></span><br>
    <button onclick="login()">登录</button>
	<button onclick="javascript:location.href='/register.html';">注册</button><br>
    <script>
        function login(){
            let uname = username.value;
            let upwd = password.value;
			
			//判断非空
			if(!uname){
				return alert('用户名不能为空');
			}
			if(!upwd){
				return alert('密码不能为空');
			}
			
            //获取对象
            let xhr = new XMLHttpRequest();
            //接收响应，打开监听
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4 && xhr.status == 200){
                    let data = xhr.responseText;
                    if(data == 1){
						alert('登录成功');
						location.href = '/list.html';
                    }else{
						alert("登录失败");
					}
                }
            };
            //打开连接
            xhr.open('get',`/pro/v1/login/${uname}&${upwd}`,true);
            //发送请求
            xhr.send();
        }
    </script>
</body>
</html>